package com.gg.user.contorller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.gg.beanhelper.BeanHelper;
import com.gg.entity.User;
import com.gg.user.service.UserService;

import helpers.baseservlet.BaseServlet;


@WebServlet("/user/RegistUserServlet")
public class RegistUserServlet extends BaseServlet {
	@Autowired
	private UserService userservice;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		User user = BeanHelper.getBean(request.getParameterMap(), User.class);
		Map<Boolean, String> resmap = userservice.regist(user);
		List<Boolean> list = new ArrayList<Boolean>(resmap.keySet());
		boolean res = list.get(0);
		request.setAttribute("msg", resmap.get(res));
		if (res) {
			request.setAttribute("code", "suc");

		} else {
			request.setAttribute("code", "err");

		}
		request.getRequestDispatcher("/msg.jsp").forward(request, response);

	}

}
